//
//  TTOAutoProgress.swift
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/20.
//  Copyright © 2016年 陶路路. All rights reserved.
//

import UIKit

class TTOAutoProgress: UIProgressView {

    var isAnima:Bool = true
    
    var timer:NSTimer?
    
    override init(frame: CGRect) {
        
        super.init(frame: CGRect(x: 0, y: 64, width: 375, height: 2))
        
        self.tintColor = UIColor.greenColor()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func starAnima(){
        
        self.progress = 0
        self.hidden = false
        timer = NSTimer.scheduledTimerWithTimeInterval(1/60, target: self, selector: "valueChange", userInfo: nil, repeats: true)
    }
    
    func valueChange(){
        
        if isAnima{
            
            self.progress += 0.05
            
            if self.progress >= 0.95{
                
                self.progress = 0.95
            }
            
        }else{
            
            self.progress = 1
            
            timer?.invalidate()
            
            self.hidden = true
        }
        
        
    }
    
    func endAnima(){
        
        isAnima = false
    }
    
    func remove(){
        
        removeFromSuperview()
    }
    
    deinit{
        
        timer?.invalidate()
       
    }
}
